package com.liu.ai.embedding;

import org.springframework.ai.ollama.OllamaEmbeddingModel;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaOptions;

public class OllamaEmbedding {

    public static void main(String[] args) {
        OllamaApi ollamaApi = OllamaApi.builder()
                .baseUrl("http://localhost:11434")
                .build();

        OllamaOptions options = OllamaOptions.builder()
                .model("zyw0605688/gte-large-zh:latest")
                .truncate(false)  //超过上下文长度，则返回错误。
                .build();

        OllamaEmbeddingModel embeddingModel = OllamaEmbeddingModel.builder()
                .ollamaApi(ollamaApi)
                .defaultOptions(options)
                .build();

        float[] embed = embeddingModel.embed("我是向量模型");
        System.out.println("返回向量长度：" + embed.length);

    }
}
